package com.homegoods.designer;

import com.homegoods.area.model.SubModelList;
import com.homegoods.classify.model.Constant;
import com.homegoods.designer.model.DesignerHomeModel;
import com.homegoods.resource.HomeGoodsApp;
import com.network.retrofit_rx.Api.ActionSubscriber;
import com.network.retrofit_rx.Api.CommandImpl;
import com.network.retrofit_rx.Api.HttpManager;

import org.json.JSONObject;

import java.util.List;
import java.util.Map;

import io.reactivex.functions.Consumer;

public class DesignerApiUtils {
    /**
     * 获取找设计师列表
     *
     * @param
     * @param
     * @param consumer AppType=Designer_region_type_offer  //Designer_是固定传值，region后面接地区，按地区搜索，type后面接类型，设计师类型 0公司1个人，offer后面接报价区间；按报价区间搜索
     *                 outdata=jsonlist   //数据传输方式
     */
    public static void getDesignerList(String region, String type, String offer, Consumer<SubModelList> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.GET_DESIGNER_LIST)
                .addParams("AppType", "Designer_region" + region + "_type" + type + "_offer" + offer)
                .addParams("outdata", "jsondata")
                .setObject(true)
                .setClass(SubModelList.class)
                .create();
        HttpManager.getInstance().get(command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取设计师主页详情
     *
     * @param
     * @param
     * @param consumer cmd=Homepage       //方法名，固定传Homepage
     *                 outdata=jsondata   //数据返回方式
     *                 sid=00
     */
    public static void getDesignerDetails(String sid, Consumer<DesignerHomeModel> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.GET_DESIGNER_DETAILS)
                .addParams("cmd", "Homepage")
                .addParams("outdata", "jsondata")
                .addParams("sid", sid)
                .setObject(true)
                .setClass(DesignerHomeModel.class)
                .create();
        HttpManager.getInstance().get(command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取设计师我的作品
     *
     * @param error AppType=Production_     //方法参数固定传
     *              token=000000            //用户token身份验证
     *              outdata=jsonlist        //数据传输方式
     */
    public static void getMyStylistWorkList(Consumer<SubModelList> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.GET_DESIGNER_LIST)
                .addParams("AppType", "Production_")
                .addParams("token", HomeGoodsApp.getToken())
                .addParams("outdata", "jsonlist")
                .setObject(true)
                .setClass(SubModelList.class)
                .create();
        HttpManager.getInstance().get(command, new ActionSubscriber<>(consumer, error, null));
    }
    /**
     * 获取设计师主页详情
     *
     * @param
     * @param
     * @param consumer
     * cmd=Adddesigner      //方法名
     * outdata=jsonlist     //数据防护方式
     * category=0           //0代码设计机构，1代表独立设计师
     * corp=格力        //公司信息：只有当申请设计机构才传
     * city=上海            //所在城市
     * name=张三            //真实姓名
     * sex=0                //0代表男，1代表女
     * phone=13122937698    //手机号
     * mailbox=@qq.cpm      //邮箱
     * rates=0              //收费标准
     * cost=90              //平均造价
     * yearsizao=0          //年均私宅数
     * decoration=0         //总共家装数量
     * construction=0       //0做过施工，1没有
     * comers=1990-09  //入行年份注：只有当申请独立设计师才传
     */
    public static void addDesigner(Map<String, Object> params, Consumer<JSONObject> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.GET_DESIGNER_DETAILS)
                .putParams(params)
                .setObject(true)
                .setClass(JSONObject.class)
                .create();
        HttpManager.getInstance().post(command, new ActionSubscriber<>(consumer, error, null));
    }

}
